package org.example.com.entity;

import org.example.com.annotation.LotSizeStrategy;
import org.example.com.annotation.MRPAnnotations;

/**
 * 物料类
 */
@MRPAnnotations.MRPEntity("物料")
public class Item {
    @MRPAnnotations.MRPField(description = "物料编号")
    private String itemId;
    @MRPAnnotations.MRPField(description = "物料名称")
    private String itemName;
    @MRPAnnotations.MRPField(description = "物料提前期")
    private int leadTime;
    @MRPAnnotations.MRPField(description = "是否为最终产品")
    private boolean finishedGood;
    @MRPAnnotations.MRPField(description = "批量策略")
    private LotSizeStrategy lotSizeStrategy;
    @MRPAnnotations.MRPField(description = "固定批量大小")
    private int fixedLotSize;     // 仅当 lotSizeStrategy 为 FIXED_LOT_SIZE 时使用
    @MRPAnnotations.MRPField(description = "倍数基数")
    private int multipleOfFixed;  // 仅当 lotSizeStrategy 为 MULTIPLE_OF_FIXED 时使用
//    @MRPAnnotations.MRPField(description = "经济批量值")
//    private int eoqQuantity;      // 可选，仅当 lotSizeStrategy 为 ECONOMIC_ORDER_QUANTITY 时使用
    @MRPAnnotations.MRPField(description = "年需求量")
    private double annualDemand = 1000;
    @MRPAnnotations.MRPField(description = "每次订货成本")
    private double orderingCost = 50;
    @MRPAnnotations.MRPField(description = "单位库存持有成本")
    private double holdingCost = 2;
    @MRPAnnotations.MRPField(description = "需求率")
    private double demandRate = 20;
    @MRPAnnotations.MRPField(description = "安全库存量")
    private int safetyStock = 2000;

    // EOQ 计算方法
    public int calculateEoq() {
        return (int) Math.ceil(Math.sqrt((2 * annualDemand * orderingCost) / holdingCost));
    }

    //计算再进货点
    public int calculateReorderPoint() {
        return (int)(demandRate*leadTime) + safetyStock;
    }

    public Item(String itemId, String itemName, int leadTime, boolean finishedGood, LotSizeStrategy lotSizeStrategy, int fixedLotSize, int multipleOfFixed) {
        this.itemId = itemId;
        this.itemName = itemName;
        this.leadTime = leadTime;
        this.finishedGood = finishedGood;
        this.lotSizeStrategy = lotSizeStrategy;
        this.fixedLotSize = fixedLotSize;
        this.multipleOfFixed = multipleOfFixed;
    }


    public String getItemId() { return itemId; }
    public void setItemId(String itemId) { this.itemId = itemId; }

    public String getItemName() { return itemName; }
    public void setItemName(String itemName) { this.itemName = itemName; }

    public int getLeadTime() { return leadTime; }
    public void setLeadTime(int leadTime) { this.leadTime = leadTime; }

    public boolean isFinishedGood() { return finishedGood; }
    public void setFinishedGood(boolean finishedGood) { this.finishedGood = finishedGood; }

    public LotSizeStrategy getLotSizeStrategy() { return lotSizeStrategy; }
    public void setLotSizeStrategy(LotSizeStrategy lotSizeStrategy) { this.lotSizeStrategy = lotSizeStrategy; }

    public int getFixedLotSize() { return fixedLotSize; }
    public void setFixedLotSize(int fixedLotSize) { this.fixedLotSize = fixedLotSize; }

    public int getMultipleOfFixed() { return multipleOfFixed; }
    public void setMultipleOfFixed(int multipleOfFixed) { this.multipleOfFixed = multipleOfFixed; }
    public double getDemandRate() { return demandRate; }
    public void setDemandRate(double demandRate) { this.demandRate = demandRate; }
    public int getSafetyStock() { return safetyStock; }
    public void setSafetyStock(int safetyStock) { this.safetyStock = safetyStock; }

}